Program for calculating E
A program for calculating E in C++, in a stupid way no doubt.
#include
#include
using namespace std;
int main() {
double sum=0;
for(double x=1;x<10;x=x+0.000000001) {
double y = 1/x;
sum += 0.000000001*y;
if(sum >= 1) {
cout << "E: " << setprecision(15) << x << endl;
return 0;
}
}
}
[/sourcecode]
Another method:
[sourcecode language="cpp"]
#include
#include
using namespace std;
int main() {
double e=1;
for(double n=0;n<=1;n=n+0.000000001) {
e=e+(e*0.000000001);
}
cout << "E: " << setprecision(15) << e << endl;
}
[/sourcecode]